package cc.fostion.photoselector.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import cc.fostion.photoselector.PhotoSelector;
import cc.fostion.photoselector.utils.L;
import cc.fostion.photoselector.utils.SelectPhotoHelper;

/**
 * 图片获取
 * Created by fostion on 5/13/16.
 */
public class SelectActivity extends Activity {
    private SelectPhotoHelper selectPhotoHelper;
    private final int REQUESTCODE = 51216;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setUpView();
    }

    private void setUpView() {
        selectPhotoHelper = new SelectPhotoHelper(this, new SelectPhotoHelper.OnGetPhotoListener() {
            @Override
            public void onSuccess(String path) {
                //获取头像成功后返回
                if(path != null && !path.isEmpty()){
                    PhotoSelector.gotoEditor(SelectActivity.this,path);
                }
            }

            @Override
            public void onFail(SelectPhotoHelper.Status status) {
                //失败返回通知
                L.e("无法获取图片");
            }
        });

        selectPhotoHelper.useSource(SelectPhotoHelper.Source.Camera);
        selectPhotoHelper.useSource(SelectPhotoHelper.Source.PhotoGallery);
        selectPhotoHelper.show();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if(selectPhotoHelper != null){
            selectPhotoHelper.onActivityResult(requestCode,resultCode,data);
        }
    }
}
